package com.org.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.org.model.Administrator;
import com.org.model.User;
import com.org.mapper.UserMapper;
import com.org.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author test
 * @since 2021-06-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper mapper;
    @Autowired
    private IUserService service;

    @Override
    public List<User> selectAll() {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.isNotNull("name");
        List<User> maps = mapper.selectList(query);
        return maps;
    }

    @Override
    public IPage<User> selectAllPage(Integer current,Integer size) {
        Page<User> page = new Page<>(current, size);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        IPage<User> userIPage = mapper.selectPage(page, queryWrapper);
        return userIPage;
    }

    @Override
    public String getFromId(Integer u_id) {
        User user = mapper.selectById(u_id);
        return user.getName();
    }

    @Override
    public User getByName(String name) {
        return mapper.getByName(name);
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id);
    }

    @Override
    public User getByAccount(String username) {
        return mapper.getByAccount(username);
    }
}
